//
//  YFShopkeeperOrderVC.m
//  QuanJieShopProject
//
//  Created by apple on 2018/5/29.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "YFShopkeeperOrderVC.h"
#import "YFShopkeeperOrderCell.h"
#import "UIScrollView+EmptyDataSet.h"
@interface YFShopkeeperOrderVC ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetDelegate,DZNEmptyDataSetSource>
@property (nonatomic, strong) NSMutableArray *dataArr;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, copy) NSString *shopID;

@end

@implementation YFShopkeeperOrderVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"订单管理";
    
    [self.view addSubview:self.tableView];
    

    NSDictionary *dic = [NSMutableDictionary new];
    [dic setValue:@"" forKey:@"sign"];
    
    [WWNetRequest fetchShopkeeperMessWithParameters:dic success:^(id response) {
        
        
        if (response) {
            
           self.shopID = [NSString stringWithFormat:@"%@",response[@"data"][@"id"]];
            NSMutableDictionary *dict = [NSMutableDictionary dictionary];
            
            NSString *shopId = [NSString stringWithFormat:@"%@",_shopID];
            [dict setObject:shopId forKey:@"shop_id"];

            [WWNetRequest fetchOrderListWithParameters:dict success:^(id response) {
                NSLog(@"订单列表 response = %@", response);
               
                NSArray *dataArr = response[@"0"][@"order_list"];
                
                for (NSDictionary *dict in dataArr) {
                    // 店铺信息
                    MineOrderModel *model = [[MineOrderModel alloc] initWithDictionary:dict error:nil];
                    NSArray *goodsArr = dict[@"goods_list"];
                    NSMutableArray *subArr = [NSMutableArray array];
                    for (NSDictionary *detailDict in goodsArr) {
                        MineOrderDetailModel *detailModel = [[MineOrderDetailModel alloc] initWithDictionary:detailDict error:nil];
                        [subArr addObject:detailModel];
                    }
                    model.detailArr = subArr;
                    [self.dataArr addObject:model];
                }

            } failure:^(NSDictionary *error) {
                NSLog(@"订单列表 error = %@", error);
            }];
        }
        
    } failure:^(NSDictionary *error) {
        
    }];

}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
}

#pragma mark - delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.dataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    YFShopkeeperOrderCell *cell = [YFShopkeeperOrderCell cellWithTableView:tableView];
    return cell;
    
    
//    YFBrowseRecordCell *cell = [YFBrowseRecordCell cellWithTableView:tableView];
//    cell.model = self.dataArr[indexPath.row];
//    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//    QJShopDetailVC *VC = [QJShopDetailVC new];
//    YFBrowseRecordModel *model = self.dataArr[indexPath.row];
//    VC.goodsID = [NSString stringWithoutNilFormart:model.goods_id];
//    KPushViewControllerAction(VC);
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 200;
}

#pragma mark - 懒加载
- (UITableView *)tableView{
    if (!_tableView) {
//        CGFloat top = IS_iOS11Later ? Height_NavBar : 0;
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH, UISCREEN_HEIGHT)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.contentInset = UIEdgeInsetsMake(0, 0, 60, 0);
    }
    return _tableView;
}

ARRAY_INIT(dataArr);
@end
